package data.xml.parser;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URL;

//import javax.xml.stream.XMLEventReader;
//import javax.xml.stream.XMLInputFactory;
//import javax.xml.stream.XMLStreamException;

public class XmlSchemaTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		File xmlFile = new File(getURL("data/xml/rune/ExampleRune.xml").getFile());
		File xsdFile = new File(getURL("data/xml/rune/rune.xsd").getFile());
		
//		XMLInputFactory factory = javax.xml.stream.XMLInputFactory.newInstance();
//		XMLEventReader xml = null;
//		XMLEventReader xsd = null;
//		try {
//			xml = factory.createXMLEventReader(new FileInputStream(xmlFile));
//			xsd = factory.createXMLEventReader(new FileInputStream(xsdFile));
//		} catch (FileNotFoundException e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		} catch (XMLStreamException e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}
		
		if (xmlFile.exists() && xsdFile.exists()) {
			try {
				boolean valid = data.xml.parser.XmlUtil.validateXmlAgainstScheme(new FileInputStream(xmlFile), new FileInputStream(xsdFile));
				String result = (valid) ? "XML is valid!" : "XML not valid!";
				System.out.println(result);
			} catch (FileNotFoundException e) {
			}
		} else {
			System.out.println("Files do not exist!");
		}

	}
	
	private static URL getURL(String relativePath) {
		return XmlSchemaTest.class.getClassLoader().getResource(relativePath);
	}
}
